/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Request, Response } from 'express';
import { ResponseItem, responseSuccess } from '../utils';
import Mock from 'mockjs';

const Random = Mock.Random;
const { mock } = Mock;
export default {
  'POST /jdk/home/applyUserList': (req: Request, res: Response) => {
    const { isDown = 0 } = req.body;
    const data = Mock.mock({
      'list|1-30': [
        {
          id: '@id()',
          created_at: '@now()',
          resources: Random.cname(),
          address: Random.cname(),
          salesman: Random.cname(),
          name: Random.cname(),
          phone: '@id()',
          message: '备注',
        },
      ],
    });

    let result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        ...data,
        total: data.list.length,
      },
    };

    return res.json(
      isDown == 1
        ? {
            ...result,
            data: 'http://upload.kuaidihelp.com/admin/bond/csv/2021/12/保证金管理数据导出_20211229154844.csv',
          }
        : result,
    );
  },
  'POST /jdk/League/list': (req: Request, res: Response) => {
    const { pageSize = 20 } = req.body;
    const data = Mock.mock({
      [`list|${pageSize}`]: [
        {
          league_id: '@id()',
          league_name: '@cword(5, 10)',
          phone: '13783636925',
          contact_phone: '13783636924',
          contact_name: '@cname(3)',
          address: ['330000000000', '330100000000', '330105000000', '330105001000'],
          agent_area_name: [
            {
              province: '上海市',
              city: '上海市',
              district: '长宁区',
              town: ['华阳路街道', '江苏路街道', '周家桥街道', '天山路街道'],
            },
          ],
          agent_area_code: [
            ['330000000000', '330100000000', '330105000000', '330105001000'],
            ['330000000000', '330100000000', '330105000000', '330105002000'],
          ],
          created_at: '@date()',
          operator: '@cname(3)',
          detail: '@county(true)',
          level: 2,
          'user_count|1-100': 100,
          province: '省',
          city: '市',
          district: '区',
          town: '街道',
          'is_black|1': ['0', '1'],
          'service_fee_enable|1': ['0', '1'],
          'service_fee_expire_type|1': ['1m', '3m', '6m'],
          'shunfen|1': [{ type: 2, brands: ['ddks'], time: 30 }],
          'account_type|1': [1, 2], // 1: 服务商、加盟商 2:蜂鸟站点
        },
      ],
    });

    let result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        ...data,
        total: data.list.length * 2,
      },
    };
    return res.json(result);
  },
  'POST /jdk/League/save': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/getAddress': (req: Request, res: Response) => {
    return res.json({
      code: 0,
      msg: '成功',
      data: [
        {
          id: '1',
          name: '上海市',
          code: '310000000000',
          pid: '0',
          level: '0',
          children: [
            {
              id: '2',
              name: '上海市',
              code: '310100000000',
              pid: '1',
              level: '1',
              children: [
                {
                  id: '6',
                  name: '长宁区',
                  code: '310105000000',
                  pid: '2',
                  level: '2',
                  children: [
                    {
                      id: '882431',
                      name: '南京东路街道',
                      code: '310101002000',
                      pid: '6',
                      level: '3',
                    },
                    { id: '882423', name: '其他', code: '310101002001', pid: '6', level: '3' },
                  ],
                },
              ],
            },
          ],
        },
        {
          id: '334',
          name: '浙江省',
          code: '330000000000',
          pid: '0',
          level: '0',
          children: [
            {
              id: '336',
              name: '杭州市',
              code: '330100000000',
              pid: '334',
              level: '1',
              children: [
                {
                  id: '338',
                  name: '拱墅区',
                  code: '330105000000',
                  pid: '336',
                  level: '2',
                  children: [
                    {
                      id: '882668',
                      name: '米市巷街道',
                      code: '330105001000',
                      pid: '338',
                      level: '3',
                    },
                  ],
                },
              ],
            },
          ],
        },
      ],
    });
  },
  'POST /jdk/League/freightConfigInfo': (req: Request, res: Response) => {
    const data = Mock.mock({
      '1': {
        id: '@id()',
        'ratio|1': ['', '60', '100'],
        'base_price|1': ['20', '30'],
        'ladder_enable|1': ['1', '2'],
        ladder_price: [
          {
            min: '0',
            max: '50',
            ratio: '90',
          },
          {
            min: '50',
            max: '100',
            ratio: '80',
          },
          {
            min: '100',
            max: '+',
            ratio: '70',
          },
        ],
      },
      '2': {
        id: '@id()',
        'ratio|1': ['', '60', '100'],
        'base_price|1': ['20', '30'],
        'ladder_enable|1': ['1', '2'],
        ladder_price: [
          {
            min: '0',
            max: '3',
            'ratio|1': ['', '60', '100'],
            'price|1': ['0', '18'],
          },
          {
            min: '3',
            max: '+',
            'ratio|1': ['', '60', '100'],
            'price|1': ['0', '5'],
          },
        ],
      },
      '3': {
        id: '@id()',
        'ratio|1': ['', '60', '100'],
        'base_price|1': ['20', '30'],
        'ladder_enable|1': ['1', '2'],
        calculation_rule: '3',
      },
      '4': {
        id: '@id()',
        'ratio|1': ['', '60', '100'],
        'base_price|1': ['20', '30'],
        'ladder_enable|1': ['1', '2'],
        ladder_price: [
          {
            min: 0,
            max: 1000,
            price: 15,
          },
          {
            min: 1000,
            max: 2000,
            price: 17,
          },
          {
            min: 2000,
            max: 3000,
            price: 18,
          },
          {
            min: 3000,
            max: '+',
            price: 20,
          },
        ],
      },
    });

    let result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: data,
    };
    return res.json(result);
  },
  'POST /jdk/League/freightConfigSave': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/home/getRemarkList': (req: Request, res: Response, u: string) => {
    //kb_id/remark_date/kb_type
    const result = mock({
      code: 0,
      msg: '成功',
      'data|2': [
        {
          id: '@id()',
          remark: '@cname()',
          created_at: '@date()',
          operator_name: '@cname()',
          operator_mobile: '15649709989',
        },
      ],
    });
    return res.json(result);
  },
  'POST /jdk/home/saveRemark': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/unLeagueBlack': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/leagueBlack': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/getLeagueRemarkList': (req: Request, res: Response, u: string) => {
    //kb_id/remark_date/kb_type
    const result = mock({
      code: 0,
      msg: '成功',
      'data|2': [
        {
          id: '@id()',
          user_id: '@id()',
          remark: '@cname()',
          create_time: '@date()',
          operate_name: '@cname()',
          operate_phone: '15649709989',
          'type|1': ['league'],
        },
      ],
    });
    return res.json(result);
  },
  'POST /jdk/League/leagueRemark': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/enableLeagueServiceFee': (req: Request, res: Response) =>
    responseSuccess(req, res),
  'POST /jdk/League/setRiderSwitch': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/allowLogin': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/allowSetDeliveryStatus': (req: Request, res: Response) =>
    responseSuccess(req, res),
  'POST /jdk/League/detail': (req: Request, res: Response) => {
    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: mock({
        league_name: '服务商名称',
        contact_name: '联系人',
        'level|1': ['省级', '市级', '区县', '乡镇', '其他'],
        'is_black|1': ['0', '1'],
        phone: '@phone',
        contact_phone: '@phone',
        address: '@county(true)',
        league_id: '@id',
        'allow_login|1': ['0', '1'],
        'service_fee_enable|1': ['0', '1'],
        'service_fee_expire_type|1': ['1m', '3m', '6m'],
        'allow_set_delivery_status|1': ['0', '1'],
        'shunfen|1': [{ type: 2, brands: ['sto'], time: 30 }],
      }),
    };
    return res.json(result);
  },
  'POST /jdk/League/getDeliveryMarkup': (req: Request, res: Response) => {
    const result: ResponseItem = mock({
      code: 0,
      msg: '成功',
      data: {
        head: [
          {
            code: 'ddks',
            name: '达达',
          },
          {
            code: 'fnpt',
            name: '蜂鸟',
          },
          {
            code: 'kfw',
            name: '快服务',
          },
          {
            code: 'mtpt',
            name: '美团配送',
          },
          {
            code: 'sftc',
            name: '顺丰同城',
          },
          {
            code: 'ss',
            name: '闪送',
          },
          {
            code: 'uupt',
            name: 'UU跑腿',
          },
          {
            code: 'gxd',
            name: '裹小递',
          },
          {
            code: 'apt',
            name: '爱跑腿',
          },
          {
            code: 'blpt',
            name: '帮啦跑腿',
          },
          {
            code: 'ccs',
            name: '曹操送',
          },
          {
            code: 'ggkj',
            name: '裹裹科技',
          },
          {
            code: 'tcjs',
            name: '同城急送',
          },
          {
            code: 'kpz',
            name: 'kpz',
          },
          {
            code: 'ldpt',
            name: '来答跑腿',
          },
          {
            code: 'mtzb',
            name: '美团众包',
          },
          {
            code: 'mtzs',
            name: '美团专送',
          },
          {
            code: 'hlks',
            name: '哈啰快送',
          },
        ],
        list: {
          ddks: {
            price: 10,
            ratio: 40,
            brand: 'ddks',
          },
          fnpt: {
            price: 14,
            ratio: 45,
            brand: 'fnpt',
          },
          kfw: [],
          mtpt: [],
          sftc: {
            price: 30,
            ratio: 30,
            brand: 'sftc',
          },
          ss: [],
          uupt: [],
          gxd: [],
          apt: [],
          blpt: [],
          ccs: [],
          ggkj: [],
          tcjs: [],
          kpz: [],
          ldpt: [],
          mtzb: [],
          mtzs: [],
          hlks: [],
        },
      },
    });
    return res.json(result);
  },
  'POST /jdk/League/getMerchantPlatformMarkup': (req: Request, res: Response) => {
    const result: ResponseItem = mock({
      code: 0,
      msg: '成功',
      data: {
        head: [
          {
            code: 'ddks',
            name: '达达',
          },
          {
            code: 'fnpt',
            name: '蜂鸟',
          },
          {
            code: 'kfw',
            name: '快服务',
          },
          {
            code: 'mtpt',
            name: '美团配送',
          },
          {
            code: 'sftc',
            name: '顺丰同城',
          },
          {
            code: 'ss',
            name: '闪送',
          },
          {
            code: 'uupt',
            name: 'UU跑腿',
          },
          {
            code: 'gxd',
            name: '裹小递',
          },
          {
            code: 'apt',
            name: '爱跑腿',
          },
          {
            code: 'blpt',
            name: '帮啦跑腿',
          },
          {
            code: 'ccs',
            name: '曹操送',
          },
          {
            code: 'ggkj',
            name: '裹裹科技',
          },
          {
            code: 'tcjs',
            name: '同城急送',
          },
          {
            code: 'kpz',
            name: 'kpz',
          },
          {
            code: 'ldpt',
            name: '来答跑腿',
          },
          {
            code: 'mtzb',
            name: '美团众包',
          },
          {
            code: 'mtzs',
            name: '美团专送',
          },
          {
            code: 'hlks',
            name: '哈啰快送',
          },
        ],
        list: {
          ddks: {
            price: 10,
            ratio: 40,
            brand: 'ddks',
          },
          fnpt: {
            price: 14,
            ratio: 45,
            brand: 'fnpt',
          },
          kfw: [],
          mtpt: [],
          sftc: {
            price: 30,
            ratio: 30,
            brand: 'sftc',
          },
          ss: [],
          uupt: [],
          gxd: [],
          apt: [],
          blpt: [],
          ccs: [],
          ggkj: [],
          tcjs: [],
          kpz: [],
          ldpt: [],
          mtzb: [],
          mtzs: [],
          hlks: [],
        },
      },
    });
    return res.json(result);
  },
  'POST /jdk/League/setDeliveryMarkup': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/setMerchantPlatformMarkup': (req: Request, res: Response) =>
    responseSuccess(req, res),
  'POST /jdk/League/setDeliveryStatus': (req: Request, res: Response) => responseSuccess(req, res),
  'POST /jdk/League/getFreeServiceFeeBrandList': (req: Request, res: Response) => {
    const data = {
      ddks: '达达',
      fnpt: '蜂鸟',
      kfw: '快服务',
      mtpt: '美团配送',
      sftc: '顺丰同城',
      ss: '闪送',
      uupt: 'UU跑腿',
      gxd: '裹小递',
      apt: '爱跑腿',
      blpt: '帮啦跑腿',
      ccs: '曹操送',
      ggkj: '裹裹科技',
      tcjs: '同城急送',
      kpz: 'kpz',
      ldpt: '来答跑腿',
      mtzb: '美团跑腿',
      mtzs: '美团专送',
      hlks: '哈啰快送',
      jfkp: '飓风快跑',
    };
    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: mock(
        Object.keys(data).map((item) => ({
          code: item,
          name: data[item],
          'free|1': [0, 1],
          'type|1': [0, 1],
        })),
      ),
    };
    return res.json(result);
  },
  'POST /jdk/League/setFreeServiceFeeBrandList': (req: Request, res: Response) =>
    responseSuccess(req, res),
};
